<!doctype html>
<html>
<head>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">
<title>指尖惊喜</title>
<link href="css/style.css" type="text/css" rel="stylesheet" />
<link href="css/reward.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery.pager.js"></script>
<script type="text/javascript" src="js/gbRst.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/utils.js"></script>
<script type="text/javascript" src="js/header&footer.js"></script>
<script type="text/javascript" src="js/qmsk-1.2.js"></script>
<script type="text/javascript" src="js/openId1.js"></script>
<!-- <script type="text/javascript" src="js/alert.js"></script>
 --><script type="text/javascript">
/*
	奖项Id
	一等奖  1
	二等奖  2
	三等奖 3
	四等奖  4
	
*/

var _prizeList= new Array();
var _zpShow = new Array()
$(function(){
	
	getLastSwp(_shopId)
	$("#shade1,#zjMessage").click(function(){
		$("#shade1,#zjMessage").hide()
	})
})

var _allPrize= new Array("很遗憾，这次您未抽中奖","恭喜您抽中的一等奖","恭喜您抽中的二等奖","恭喜您抽中的三等奖","恭喜您抽中的四等奖","恭喜您抽中的五等奖","恭喜您抽中的六等奖","恭喜您抽中的七等奖");
function getLastSwp(shopId){
	$.ajax({
		url:'../sweepstakes/find/cjType',
		type:'get',
		data:{'typeId':1},
		success:function(data){
		var dt = JSON.parse(data);
			if(dt.state==0){
				if(dt.result.data.length==0){
				alert("暂无抽奖")
				}else{
				 swptaksID = getHtmlString(getHeadIndexValue(0, dt, "swptaksID"))
				 $("#content").html(getHtmlString(getHeadIndexValue(0, dt, "swptaksContent")))
					getPrizeBySwpId(swptaksID);
				}
			}else{
			alert("查看活动出错")	
			}
		}
	})
	
}

function getPrizeBySwpId(swpId){
	$.ajax({
		url:'../sweepstakes/find/allPrize/'+swpId,
		type:'get',
		success:function(data){
		var dt = JSON.parse(data);
			if(dt.state==0){
				if(dt.result.data.length==0){
				alert("暂无抽奖")
				}else{
					for ( var i = 0; i < dt.result.data.length; i++) {
						var prizeNameAndLevel = getHtmlString(getHeadIndexValue(i, dt, "prizelvName")) +"："+getHtmlString(getHeadIndexValue(i, dt, "PrizeName"))+"<br>"
						$("#prizeList").append( prizeNameAndLevel)
						var prizeID = getHtmlString(getHeadIndexValue(i, dt, "PrizeLvId"))
						_prizeList.push(prizeID)
					}
					
					var m =8-_prizeList.length;
					
					var jd = -23;
					for ( var i = 0; i < _prizeList.length; i++) {
						
						$("#zp").append("<div class=\"awardTxt awardTxt"+_prizeList[i]+"\" style=\"-webkit-transform: rotate("+jd+"deg);-moz-transform: rotate("+jd+"deg);\" ></div>")
						jd+=45;
						_zpShow.push(_prizeList[i])
						if(m>0){
							$("#zp").append("<div class=\"awardTxt awardTxt9\" style=\"-webkit-transform: rotate("+jd+"deg);-moz-transform: rotate("+jd+"deg);\" ></div>")
						jd+=45;
							m--
							_zpShow.push(0)
						}
					}
					if(m>0){
						for ( var i = 0; i < m; i++) {
								$("#zp").append("<div class=\"awardTxt awardTxt9\" style=\"-webkit-transform: rotate("+jd+"deg);-moz-transform: rotate("+jd+"deg);\" ></div>")
							jd+=45;
								_zpShow.push(0)

						}
					}
					
				}
			}else{
			alert("查看活动出错")	
			}
		}
	})
	

	$("#lotteryBtn").rotate({ 
	   bind: 
		 { 
			click: function(){
				$("#shade").show();
				var data=0;
				$.ajax({
					url:'../sweepstakes/edit/checkPrize',
					type:'post',
					async:false,
					data:{'swpID':swptaksID,'openId':_openId,'shopId':_shopId,'swpType':1},
					success:function(data){
					var dt = JSON.parse(data);
						if(dt.state==0){
						data=getHtmlInt(getHeadIndexValue(0, dt, "data"))
						var zz=data
						if(data==-2){
							alert("今日抽奖次数已用完")
							$("#shade").hide();
							
						}else if(data==-1){
							alert("您还不是会员")
							$("#shade").hide();
							return false;
						}else if(data==-20){
							alert("积分不足无法参与抽奖")
							$("#shade").hide();
							return false;
						}
						else if(data<0){
							$("#shade").hide();
						alert("网络错误")
						}else{ 
							
						var jd=0;
						var m = 0;
						var x = 0
						for ( var i = 0; i < _zpShow.length; i++) {
							if(_zpShow[i]==0){
								x++;
							}
							if(data==_zpShow[i]){
								jd = 112+(i+1)*45;
								m=_allPrize[data]
							}
						}
						if(data==0&&x>0){
							data = Math.floor(Math.random()*x);
							x=0
							for ( var i = 0; i < _zpShow.length; i++) {
								if(_zpShow[i]==0){
									x++;
								}
								if(data==x){
									jd = 112+(i+2)*45;
								}
							}
						}
						
						rotateFunc(1,jd,m,zz)
						}
						}else{
							alert("网络错误")
							$("#shade").hide();

						}
					}
				})			
		 } 
		 }
	});
	
	var rotateFunc = function(awards,angle,text,i){  //awards:奖项，angle:奖项对应的角度
		$('#zz').stopRotate();
		$("#zz").rotate({
			angle:0, 
			duration: 5000, 
			animateTo: angle+3600, //angle是图片上各奖项对应的角度，1440是我要让指针旋转4圈。所以最后的结束的角度就是这样子^^
			callback:function(){
				$("#shade").hide();
				alert(_allPrize[i])
				/* $("#zjMessage img").attr("src",_allPrize[i])
				addMargin($("#zjMessage")) */
				$("#shade1,#zjMessage").show()
			}
		}); 
	};
	
}

</script>
</head>
<body class="activity-scratch-card-winning">
<!-- <div id="shade1" class="shade" ></div>
<div id="zjMessage" class="hideDiv" style="width:282px;border:none;padding:0;background:none;"><img src="images/18Z.png"></div> -->
<!-- <div id="shade" style="position:fixed;width:100%;height:100%;background:#FFF;opacity:0.01;left:0;top:0;z-index:500;display: none;"></div>
 --><div id="wrapper">
    <div id="container">
   <!--  <div class="only_img" style="margin-top:0;"><img src="images/dyd.jpg"></div> -->
        <div class="ly-plate">
        	<div class="award" id="zp" >
        	<!-- <div class="awardTxt awardTxt1" style="-webkit-transform: rotate(-23deg);-moz-transform: rotate(-23deg);"></div>
                <div class="awardTxt awardTxt2" style="-webkit-transform: rotate(23deg);-moz-transform: rotate(23deg);"></div>
                <div class="awardTxt awardTxt3" style="-webkit-transform: rotate(67deg);-moz-transform: rotate(67deg);"></div>
                <div class="awardTxt awardTxt9" style="-webkit-transform: rotate(112deg);-moz-transform: rotate(112deg);"></div>
                <div class="awardTxt awardTxt9" style="-webkit-transform: rotate(157deg);-moz-transform: rotate(157deg);"></div>
                <div class="awardTxt awardTxt9" style="-webkit-transform: rotate(-157deg);-moz-transform: rotate(202deg);"></div>
                <div class="awardTxt awardTxt9" style="-webkit-transform: rotate(-112deg);-moz-transform: rotate(-112deg);"></div>
                <div class="awardTxt awardTxt9" style="-webkit-transform: rotate(-67deg);-moz-transform: rotate(-67deg);"></div> -->
                </div>
             <div class="rotate-bg"></div>
            <div class="lottery-star"><img src="images/zhen.png" id="zz"></div>
        </div>
        <div class="give">
						<input type="button"  id="lotteryBtn"  value="手指抖一抖" style="line-height:14px;width:auto;padding:6px 32px;border-radius:16px;color:#fff;background:#b3040e;border:none;">
					</div>
        <div class="boxcontent boxwhite">
        <div class="box">
        <div class="title-brown"><span>奖项设置：</span></div>
        <div class="Detail" id="prizeList">
       
        </div>
        </div>
        </div>
        <div class="boxcontent boxwhite">
        <div class="box">
        <div class="title-brown">活动说明：</div>
        <div class="Detail" id="content">
        <p>本次活动每人可以转 3 次 </p>
        <p> 我们的中奖率高达33.3%！！ </p>
        </div>
        </div>
        </div>
       <!--  <div class="gameRule">
        	<h3 style="color:#b3030e;">游戏规则：</h3>
            <p>每天1次参与机会；</p>
            <p>分享到朋友圈后，即可凭分享页面至售楼部领取礼品</p>
 --><!--             <p class="tipsTxt">注：本活动最终解释权归英伦联邦所有。</p>
        </div> -->
    </div>
</div>
<script type="text/javascript" src="js/jQueryRotate.2.2.js"></script>
<script type="text/javascript" src="js/jquery.easing.min.js"></script>
<script type="text/javascript">
$(function(){
	/*var timeOut = function(){  //超时函数
		$("#lotteryBtn").rotate({
			angle:0, 
			duration: 10000, 
			animateTo: 2160, //这里是设置请求超时后返回的角度，所以应该还是回到最原始的位置，2160是因为我要让它转6圈，就是360*6得来的
			callback:function(){
				alert('网络超时')
			}
		}); 
	}; */
	
	
	addMargin($(".hideDiv"));
	
})
</script>	
</body>
</html>
